package operate;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书！");
        System.out.print("输入你要归还的书名：");
        Scanner in = new Scanner(System.in);
        String name = in.nextLine();

        for (int i = 0; i < bookList.getUsedSize(); i++) {

            //图书存在，且已被借出
            if (name.equals(bookList.getBook(i).getName()) &&
                    bookList.getBook(i).isBorrowed()) {
                bookList.getBook(i).setBorrowed(false);
                System.out.println("归还成功！");
                return;
            }
        }

        System.out.println("归还失败，"+name+"为被借出或不存在！");
    }
}
